<template>
  <div>
    <!-- mouseover(覆盖)和mouseout是常用来判断鼠标移出和移入的事件 -->
    <div class="app" v-on:mouseover="stop()">
      <!-- transition-group表示一组动画 -->
      <transition-group tag="ul" name="image">
        <li v-for="(items, index) in list" :key="index" v-show="index === num">
          <img :src="require(`../assets/images/${items}`)" alt="" />
        </li>
      </transition-group>
      <!-- 箭头 -->
      <div class="jt">
        <span @click="left"><</span>
        <span @click="right">></span>
      </div>
    </div>
    <div class="box">
      <span
        v-for="(items, index) in data"
        @click="xun(index)"
        :class="{ active: index == num }"
        >{{ items }}</span
      >
    </div>
  </div>
</template>

<script>
export default {
  name: "",
  components: {},
  data() {
    return {
      data: ["1", "2", "3"],
      list: ["b1.png", "b2.png", "b3.png"],
      num: 0,//下标
      time:''
    };
  },
  created() {
    this.getTo()
  },
  mounted() {},
  methods: {
    // 点击数字高亮显示
    xun(i) {
      this.num = i;
    },
    getTo(){
      // 定时器 num++ 判断如果到最后一张图片就重新到第一张图片
      this.time=setInterval(()=>{
        this.num++;
        if(this.num==3){
          this.num=0
        }
      },2000)
    },
    // 往后退要-- 如果小于0 就到最后一张图
    left(){
      this.num--;
      if(this.num<0){
        thi.num=2
      }
    },
    //  往前加1 等于3就显示第一张图
    right(){
      this.num++;
      if(this.num==3){
        this.num=0
      }
    },
    // 清除定时器
    stop(){
      clearInterval(this.num)
    },
  },
};
</script>
<style scoped lang='scss'>
html {
  height: 100%;
}
body {
  height: 100%;
  display: flex;
  justify-content: center;
}
.app {
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
}
.active {
  opacity: 0.2;
}
img {
  width: 550px;
  height: 300px;
}
.jt span {
  font-size: 30px;
  color: pink;
  position: relative;
  top: 300px;
}
.box span {
  color: #fff;
  background-color: red;
  margin-left: 10px;
  font-size: 20px;
  border-radius: 50%;
  padding: 0 8px;
  margin-bottom: 10px;
  // opacity: 0.2;
  position: relative;
  left: 820px;
  top: 150px;
}
.jt span:first-child {
  left: -500px;
}
.jt span:nth-child(2) {
  left: -100px;
}
li {
  width: 500px;
  height: 300px;
  position: absolute;
}
ul {
  width: 580px;
  height: 300px;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
  position: relative;
  bottom: -200px;
}
// enter-active是控制载入时的样式名的后缀
.image-enter-active {
  transition: all 0.8s linear;
}
// leave-active 是控制离开时的样式名的后缀
.image-leave-active {
  transition: all 0.8s linear;
}
// 过渡 动画进入之后的结束状态
.image-enter-to {
  transform: translateX(0);
}
// 动画进入之前的初始状态
.image-enter {
  transform: translateX(100%);
}
// 动画离开之前的初始状态
.image-leave {
  transform: translateX(0);
}
// 动画离开之后的结束状态
.image-leave-to {
  transform: translateX(-100%);
}
</style>
